package com.acme.orders.model;

import java.io.Serializable;

public class OrderLine implements Serializable {

	private static final long serialVersionUID = 4096624710857634465L;

	private String id;
	private int quantity;
	private Order order;
	private Product product;

	public String getId() {
		return id;
	}
	public Product getProduct() {
		return product;
	}
	public int getQuantity() {
		return quantity;
	}
	public Order getOrder() {
		return order;
	}

	public OrderLine setProduct(Product product) {
		this.product = product;
		return this;
	}
	public OrderLine setId(String id) {
		this.id = id;
		return this;
	}
	public OrderLine setQuantity(int quantity) {
		this.quantity = quantity;
		return this;
	}
	public OrderLine setOrder(Order order) {
		this.order = order;
		return this;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		OrderLine other = (OrderLine) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("OrderLine [");
		if (id != null)
			builder.append(id).append("| ");
		builder.append(quantity).append("| ");
		if (product != null)
			builder.append(product);
		builder.append("]");
		return builder.toString();
	}
			
}
